//
//  GetCodeViewController.m
//  meiyaya
//
//  Created by 张领瑞 on 2017/8/31.
//  Copyright © 2017年 ShiFeiEr. All rights reserved.
//

#import "GetCodeViewController.h"
#import "UIViewController+CAAnimate.h"
#import "UIViewController+UIStoryboard.h"
#import "PrefixHeader.pch"

@interface GetCodeViewController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneNumTF;
@property (weak, nonatomic) IBOutlet UITextField *codeTF;

@property (weak, nonatomic) IBOutlet UIButton *codeBT;
@end

@implementation GetCodeViewController

#pragma mark 返回上一界面
- (IBAction)backToLoginVC:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

#pragma mark 跳转至重设密码vc
- (IBAction)jumpToResetPWDVC:(id)sender {
    if ([self.phoneNumTF isMobilePhoneNumber]) {
        //验证手机验证码
        [SMSSDK commitVerificationCode:self.codeTF.text phoneNumber:self.phoneNumTF.text zone:@"86" result:^(NSError *error) {
        if (error) {//验证失败
           [self presentAlertViewWithControlTitle:@"提示" Message:@"验证码错误" ActionTitle:@"确认"];
            
        }else{//验证成功
            ResetPWDViewController *vc = (ResetPWDViewController *)[self viewControllerInMStoryboardWithName:@"Main" WithIdentifier:@"ResetPWDViewController"];
            vc.phoneNumber = self.phoneNumTF.text;//传值到ResetPWDViewController
            [self presentViewController:vc animated:YES completion:nil];
        }
    }]; 
    }else{
        [self presentAlertViewWithControlTitle:@"提示" Message:@"请输入您的手机号" ActionTitle:@"确认"];
    }
   
}
#pragma mark 取得短信验证码
- (IBAction)getCodeNum:(id)sender {

    [self getcode];
}
-(void)getcode{
    
    if ([self.phoneNumTF isMobilePhoneNumber]) {
        [self.codeBT leftSecondsShow];//展示倒计时
        //取得验证码
        [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.phoneNumTF.text zone:@"86" result:^(NSError *error) {
            if (error) {
                
                [self presentAlertViewWithControlTitle:@"提示" Message:error.localizedDescription  ActionTitle:@"确认"];
            }
        }];
    }else{
        [self presentAlertViewWithControlTitle:@"提示" Message:@"请输入您的手机号"  ActionTitle:@"确认"];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addTapGestureForViewControllerToRecoverKeyboard];//添加手势回收键盘
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
